home *** CD-ROM | disk | FTP | other *** search
/ PC Open 96 / PC Open 96 CD3.bin / fscommand / index.swf / scripts / %3Cdefault package%3E / VIDEO_NAVIGATION.as < prev   
Encoding:
Text File  |  2004-01-08  |  17.0 KB  |  552 lines

  1. _global.videoNavigationCLASS = function()
  2. {
  3.    this.init();
  4. };
  5. Object.registerClass("VIDEO_NAVIGATION",_global.videoNavigationCLASS);
  6. _global.videoNavigationCLASS.prototype = new MovieClip();
  7. _global.videoNavigationCLASS.prototype.register = function(element, target)
  8. {
  9.    var element;
  10.    if(element.toUpperCase() == "VIDEO")
  11.    {
  12.       this.videoTarget = target;
  13.    }
  14.    else if(element.toUpperCase() == "MUTE")
  15.    {
  16.       this.volumeInterval = setInterval(this,"onVolume",1000 / (_global.FPS * 2));
  17.       this.MUTE.hitArea = target;
  18.       target.gotoAndStop(1);
  19.    }
  20.    else
  21.    {
  22.       this[element].hitArea = target;
  23.       target.gotoAndStop(1);
  24.    }
  25. };
  26. _global.videoNavigationCLASS.prototype.setEnabled = function(state)
  27. {
  28.    this.PLAY.enabled = state;
  29.    this.STOP.enabled = state;
  30.    this.PAUSE.enabled = state;
  31.    this.REWIND.enabled = state;
  32.    this.FORWARD.enabled = state;
  33.    this.MUTE.enabled = state;
  34.    this.VOLUME_SLIDER.enabled = state;
  35.    this.VOLUME_SLIDER_BAR.enabled = state;
  36.    this.POSITION_SLIDER.enabled = state;
  37.    this.POSITION_SLIDER_BAR.enabled = state;
  38. };
  39. _global.videoNavigationCLASS.prototype.setOnEnd = function(target, method)
  40. {
  41.    this.onEndArgs = arguments;
  42. };
  43. _global.videoNavigationCLASS.prototype.getOnEnd = function()
  44. {
  45.    return this.onEndArgs[0][this.onEndArgs[1]];
  46. };
  47. _global.videoNavigationCLASS.prototype.onEnd = function()
  48. {
  49.    this.onEndArgs[0][this.onEndArgs[1]].apply(this.onEndArgs[0],this.onEndArgs.slice(2));
  50. };
  51. ASSetPropFlags(_global.videoNavigationCLASS.prototype,["onEnd"],1);
  52. _global.videoNavigationCLASS.prototype.unload = function()
  53. {
  54.    clearInterval(this.volumeSliderDrag);
  55.    clearInterval(this.positionSliderDrag);
  56.    clearInterval(this.rewindInterval);
  57.    clearInterval(this.forwardInterval);
  58.    clearInterval(this.endInterval);
  59.    delete this.endInterval;
  60.    Key.removeListener(this.keyListener);
  61. };
  62. _global.videoNavigationCLASS.prototype.init = function()
  63. {
  64.    this.LABEL._visible = false;
  65.    this.keyListener = new Object();
  66.    this.keyListener.controller = this;
  67.    Key.addListener(this.keyListener);
  68.    this.keyListener.onKeyDown = function()
  69.    {
  70.       if(Key.isDown(32))
  71.       {
  72.          if(this.controller.isPlaying)
  73.          {
  74.             this.controller.pauseVideo();
  75.          }
  76.          else
  77.          {
  78.             this.controller.start();
  79.          }
  80.       }
  81.       if(Key.isDown(37))
  82.       {
  83.          this.controller.onRewindPress();
  84.          this.rewindPressed = true;
  85.       }
  86.       if(Key.isDown(39))
  87.       {
  88.          this.controller.onForwardPress();
  89.          this.forwardPressed = true;
  90.       }
  91.    };
  92.    this.keyListener.onKeyUp = function()
  93.    {
  94.       if(!Key.isDown(37) && this.rewindPressed)
  95.       {
  96.          this.rewindPressed = false;
  97.          this.controller.onRewindRelease();
  98.       }
  99.       if(!Key.isDown(39) && this.forwardPressed)
  100.       {
  101.          this.forwardPressed = false;
  102.          this.controller.onForwardRelease();
  103.       }
  104.    };
  105.    this.createEmptyMovieClip("PLAY",++this.depth);
  106.    this.PLAY.controller = this;
  107.    this.PLAY.onPress = function()
  108.    {
  109.       this.controller.OnPlayPress();
  110.    };
  111.    this.PLAY.onRelease = this.PLAY.onReleaseOutside = function()
  112.    {
  113.       this.controller.OnPlayRelease();
  114.    };
  115.    this.createEmptyMovieClip("PAUSE",++this.depth);
  116.    this.PAUSE.controller = this;
  117.    this.PAUSE.onPress = function()
  118.    {
  119.       this.controller.OnPausePress();
  120.    };
  121.    this.PAUSE.onRelease = this.PAUSE.onReleaseOutside = function()
  122.    {
  123.       this.controller.OnPauseRelease();
  124.    };
  125.    this.createEmptyMovieClip("REWIND",++this.depth);
  126.    this.REWIND.controller = this;
  127.    this.REWIND.onPress = function()
  128.    {
  129.       this.controller.OnRewindPress();
  130.    };
  131.    this.REWIND.onRelease = this.REWIND.onReleaseOutside = function()
  132.    {
  133.       this.controller.OnRewindRelease();
  134.    };
  135.    this.createEmptyMovieClip("FORWARD",++this.depth);
  136.    this.FORWARD.controller = this;
  137.    this.FORWARD.onPress = function()
  138.    {
  139.       this.controller.OnForwardPress();
  140.    };
  141.    this.FORWARD.onRelease = this.FORWARD.onReleaseOutside = function()
  142.    {
  143.       this.controller.OnForwardRelease();
  144.    };
  145.    this.createEmptyMovieClip("VOLUME_SLIDER_BAR",++this.depth);
  146.    this.VOLUME_SLIDER_BAR.controller = this;
  147.    this.VOLUME_SLIDER_BAR.onPress = function()
  148.    {
  149.       this.controller.onVolumeSliderBarPress();
  150.    };
  151.    this.VOLUME_SLIDER_BAR.onRelease = this.VOLUME_SLIDER_BAR.onReleaseOutside = function()
  152.    {
  153.       this.controller.onVolumeSliderBarRelease();
  154.    };
  155.    this.createEmptyMovieClip("MUTE",++this.depth);
  156.    this.MUTE.controller = this;
  157.    this.MUTE.onPress = function()
  158.    {
  159.       this.controller.onMutePress();
  160.    };
  161.    this.MUTE.onRelease = this.MUTE.onReleaseOutside = function()
  162.    {
  163.       this.controller.OnMuteRelease();
  164.    };
  165.    this.bMute = false;
  166.    this.createEmptyMovieClip("VOLUME_SLIDER",++this.depth);
  167.    this.VOLUME_SLIDER.controller = this;
  168.    this.VOLUME_SLIDER.onPress = function()
  169.    {
  170.       this.controller.onVolumeSliderPress();
  171.    };
  172.    this.VOLUME_SLIDER.onRelease = this.VOLUME_SLIDER.onReleaseOutside = function()
  173.    {
  174.       this.controller.onVolumeSliderRelease();
  175.    };
  176.    this.nVolume = 70;
  177.    this.createEmptyMovieClip("POSITION_SLIDER_BAR",++this.depth);
  178.    this.POSITION_SLIDER_BAR.controller = this;
  179.    this.POSITION_SLIDER_BAR.onPress = function()
  180.    {
  181.       this.controller.onPositionSliderBarPress();
  182.    };
  183.    this.POSITION_SLIDER_BAR.onRelease = this.POSITION_SLIDER_BAR.onReleaseOutside = function()
  184.    {
  185.       this.controller.onPositionSliderBarRelease();
  186.    };
  187.    this.createEmptyMovieClip("POSITION_SLIDER",++this.depth);
  188.    this.POSITION_SLIDER.controller = this;
  189.    this.POSITION_SLIDER.onPress = function()
  190.    {
  191.       this.controller.onPositionSliderPress();
  192.    };
  193.    this.POSITION_SLIDER.onRelease = this.POSITION_SLIDER.onReleaseOutside = function()
  194.    {
  195.       this.controller.onPositionSliderRelease();
  196.    };
  197.    if(!this.slidePositionInterval)
  198.    {
  199.       this.slidePositionInterval = setInterval(this,"onSliderPosition",1000 / (_global.FPS / 5));
  200.    }
  201. };
  202. _global.videoNavigationCLASS.prototype.onEnterFrame = function()
  203. {
  204.    if(this.endEnterFrame)
  205.    {
  206.       this.onEndEnterFrame();
  207.    }
  208. };
  209. _global.videoNavigationCLASS.prototype.onEndEnterFrame = function()
  210. {
  211.    if(this.videotarget._currentframe == this.videotarget._totalframes)
  212.    {
  213.       clearInterval(this.endInterval);
  214.       delete this.endInterval;
  215.       this.onEnd();
  216.       this.stopVideo();
  217.    }
  218. };
  219. _global.videoNavigationCLASS.prototype.OnPlayPress = function()
  220. {
  221.    this.PLAY.hitArea.gotoAndStop("DOWN");
  222. };
  223. _global.videoNavigationCLASS.prototype.OnPlayRelease = function()
  224. {
  225.    this.start();
  226.    this.onPlayReleaseTarget[this.onPlayReleaseMethod]();
  227. };
  228. _global.videoNavigationCLASS.prototype.start = function()
  229. {
  230.    this.PLAY.hitArea.gotoAndStop("DOWN");
  231.    this.STOP.hitArea.gotoAndStop("UP");
  232.    this.PAUSE.hitArea.gotoAndStop("UP");
  233.    if(this.videotarget._currentframe == this.videotarget._totalframes)
  234.    {
  235.       this.videoTarget.gotoAndPlay(1);
  236.    }
  237.    this.endEnterFrame = true;
  238.    this.onEndInterval();
  239.    this.videoTarget.play();
  240.    this.isPlaying = true;
  241. };
  242. _global.videoNavigationCLASS.prototype.OnPausePress = function()
  243. {
  244.    this.PAUSE.hitArea.gotoAndStop("DOWN");
  245. };
  246. _global.videoNavigationCLASS.prototype.OnPauseRelease = function()
  247. {
  248.    this.pauseVideo();
  249. };
  250. _global.videoNavigationCLASS.prototype.pauseVideo = function()
  251. {
  252.    this.PLAY.hitArea.gotoAndStop("UP");
  253.    this.PAUSE.hitArea.gotoAndStop("DOWN");
  254.    this.videoTarget.stop();
  255.    this.isPlaying = false;
  256.    this.onPauseReleaseTarget[this.onPauseReleaseMethod]();
  257. };
  258. _global.videoNavigationCLASS.prototype.OnStopPress = function()
  259. {
  260.    this.STOP.hitArea.gotoAndStop("DOWN");
  261. };
  262. _global.videoNavigationCLASS.prototype.OnStopRelease = function()
  263. {
  264.    this.stopVideo();
  265. };
  266. _global.videoNavigationCLASS.prototype.stopVideo = function()
  267. {
  268.    this.PLAY.hitArea.gotoAndStop("UP");
  269.    this.PAUSE.hitArea.gotoAndStop("UP");
  270.    this.REWIND.hitArea.gotoAndStop("UP");
  271.    this.FORWARD.hitArea.gotoAndStop("UP");
  272.    this.STOP.hitArea.gotoAndStop("DOWN");
  273.    this.videoTarget.stop();
  274.    this.isPlaying = false;
  275.    this.endEnterFrame = false;
  276.    this.onStopReleaseTarget[this.onStopReleaseMethod]();
  277. };
  278. _global.videoNavigationCLASS.prototype.OnRewindPress = function()
  279. {
  280.    this.REWIND.hitArea.gotoAndStop("DOWN");
  281.    this.rewindInterval = setInterval(this,"onRewindInterval",1000 / (_global.FPS + 1));
  282.    this.rewindIntervalCount = 0;
  283.    this.onRewindInterval();
  284. };
  285. _global.videoNavigationCLASS.prototype.OnRewindRelease = function()
  286. {
  287.    this.REWIND.hitArea.gotoAndStop("UP");
  288.    clearInterval(this.rewindInterval);
  289.    this.onRewindReleaseTarget[this.onRewindReleaseMethod]();
  290. };
  291. _global.videoNavigationCLASS.prototype.onRewindInterval = function()
  292. {
  293.    if(this.RewindIntervalCount < 5)
  294.    {
  295.       if(this.isPlaying)
  296.       {
  297.          this.videoTarget.gotoAndPlay(this.videoTarget._currentframe - _global.FPS * 2);
  298.       }
  299.       else
  300.       {
  301.          this.videoTarget.gotoAndStop(this.videoTarget._currentframe - _global.FPS * 2);
  302.       }
  303.    }
  304.    else if(this.RewindIntervalCount < 20)
  305.    {
  306.       if(this.isPlaying)
  307.       {
  308.          this.videoTarget.gotoAndPlay(this.videoTarget._currentframe + _global.FPS * 4);
  309.       }
  310.       else
  311.       {
  312.          this.videoTarget.gotoAndStop(this.videoTarget._currentframe + _global.FPS * 4);
  313.       }
  314.    }
  315.    else if(this.RewindIntervalCount < 30)
  316.    {
  317.       if(this.isPlaying)
  318.       {
  319.          this.videoTarget.gotoAndPlay(this.videoTarget._currentframe - _global.FPS * 8);
  320.       }
  321.       else
  322.       {
  323.          this.videoTarget.gotoAndStop(this.videoTarget._currentframe - _global.FPS * 8);
  324.       }
  325.    }
  326.    else if(this.isPlaying)
  327.    {
  328.       this.videoTarget.gotoAndPlay(this.videoTarget._currentframe - _global.FPS * 16);
  329.    }
  330.    else
  331.    {
  332.       this.videoTarget.gotoAndStop(this.videoTarget._currentframe - _global.FPS * 16);
  333.    }
  334.    this.forwardIntervalCount = this.forwardIntervalCount + 1;
  335. };
  336. _global.videoNavigationCLASS.prototype.OnForwardPress = function()
  337. {
  338.    this.FORWARD.hitArea.gotoAndStop("DOWN");
  339.    this.forwardIntervalCount = 0;
  340.    this.forwardInterval = setInterval(this,"onForwardInterval",1000 / (_global.FPS + 1));
  341.    this.onForwardInterval();
  342. };
  343. _global.videoNavigationCLASS.prototype.OnForwardRelease = function()
  344. {
  345.    this.FORWARD.hitArea.gotoAndStop("UP");
  346.    clearInterval(this.forwardInterval);
  347.    this.onForwardReleaseTarget[this.onforwardReleaseMethod]();
  348. };
  349. _global.videoNavigationCLASS.prototype.onForwardInterval = function()
  350. {
  351.    if(this.forwardIntervalCount < 5)
  352.    {
  353.       if(this.isPlaying)
  354.       {
  355.          this.videoTarget.gotoAndPlay(this.videoTarget._currentframe + _global.FPS * 2);
  356.       }
  357.       else
  358.       {
  359.          this.videoTarget.gotoAndStop(this.videoTarget._currentframe + _global.FPS * 2);
  360.       }
  361.    }
  362.    else if(this.forwardIntervalCount < 20)
  363.    {
  364.       if(this.isPlaying)
  365.       {
  366.          this.videoTarget.gotoAndPlay(this.videoTarget._currentframe + _global.FPS * 4);
  367.       }
  368.       else
  369.       {
  370.          this.videoTarget.gotoAndStop(this.videoTarget._currentframe + _global.FPS * 4);
  371.       }
  372.    }
  373.    else if(this.forwardIntervalCount < 30)
  374.    {
  375.       if(this.isPlaying)
  376.       {
  377.          this.videoTarget.gotoAndPlay(this.videoTarget._currentframe + _global.FPS * 8);
  378.       }
  379.       else
  380.       {
  381.          this.videoTarget.gotoAndStop(this.videoTarget._currentframe + _global.FPS * 8);
  382.       }
  383.    }
  384.    else if(this.isPlaying)
  385.    {
  386.       this.videoTarget.gotoAndPlay(this.videoTarget._currentframe + _global.FPS * 16);
  387.    }
  388.    else
  389.    {
  390.       this.videoTarget.gotoAndStop(this.videoTarget._currentframe + _global.FPS * 16);
  391.    }
  392.    if(this.endEnterFrame)
  393.    {
  394.       this.onEndEnterFrame();
  395.    }
  396.    this.forwardIntervalCount = this.forwardIntervalCount + 1;
  397. };
  398. _global.videoNavigationCLASS.prototype.setVolume = function(value)
  399. {
  400.    value = Math.round(value);
  401.    if(value > 100)
  402.    {
  403.       value = 100;
  404.    }
  405.    else if(value < 0 || parseFloat(value) != value)
  406.    {
  407.       value = 0;
  408.    }
  409.    this.nVolume = value;
  410. };
  411. _global.videoNavigationCLASS.prototype.getVolume = function()
  412. {
  413.    return this.nVolume;
  414. };
  415. _global.videoNavigationCLASS.prototype.onVolume = function()
  416. {
  417.    var sTrack;
  418.    sTrack = new Sound(this.videoTarget);
  419.    if(this.bMute)
  420.    {
  421.       sTrack.setVolume(0);
  422.    }
  423.    else
  424.    {
  425.       sTrack.setVolume(this.nVolume);
  426.    }
  427.    this.VOLUME_SLIDER.hitArea._x = this.VOLUME_SLIDER_BAR.hitArea._x + this.VOLUME_SLIDER_BAR.hitArea._width / 100 * this.nVolume;
  428. };
  429. _global.videoNavigationCLASS.prototype.onVolumeSliderBarPress = function()
  430. {
  431.    this.volumeSliderDrag = setInterval(this,"onVolumeSliderDrag",20);
  432. };
  433. _global.videoNavigationCLASS.prototype.onVolumeSliderBarRelease = function()
  434. {
  435.    var sTrack;
  436.    clearInterval(this.volumeSliderDrag);
  437.    this.onVolumeSliderBarTarget[this.onVolumeSliderBarMethod](this.nVolume);
  438. };
  439. _global.videoNavigationCLASS.prototype.onMutePress = function()
  440. {
  441.    if(this.bMute)
  442.    {
  443.       this.MUTE.hitArea.gotoAndStop("UP");
  444.    }
  445.    else
  446.    {
  447.       this.MUTE.hitArea.gotoAndStop("DOWN");
  448.    }
  449. };
  450. _global.videoNavigationCLASS.prototype.onMuteRelease = function()
  451. {
  452.    var sTrack;
  453.    sTrack = new Sound(this.videoTarget);
  454.    if(this.bMute)
  455.    {
  456.       this.bMute = false;
  457.       this.onVolume();
  458.    }
  459.    else
  460.    {
  461.       this.bMute = true;
  462.       this.onVolume();
  463.    }
  464.    this.onMuteReleaseTarget[this.onMuteReleaseTargetMethod](this.bMute);
  465. };
  466. _global.videoNavigationCLASS.prototype.onVolumeSliderPress = function()
  467. {
  468.    this.volumeSliderDrag = setInterval(this,"onVolumeSliderDrag",20);
  469. };
  470. _global.videoNavigationCLASS.prototype.onVolumeSliderRelease = function()
  471. {
  472.    clearInterval(this.volumeSliderDrag);
  473.    this.onVolumeSliderTarget[this.onVolumeSliderMethod](this.nVolume);
  474. };
  475. _global.videoNavigationCLASS.prototype.onVolumeSliderDrag = function()
  476. {
  477.    updateAfterEvent();
  478.    var volume = this.VOLUME_SLIDER_BAR.hitArea._parent._xmouse - this.VOLUME_SLIDER_BAR.hitArea._x;
  479.    volume /= this.VOLUME_SLIDER_BAR.hitArea._width / 100;
  480.    this.setVolume(volume);
  481. };
  482. _global.videoNavigationCLASS.prototype.setSliderPosition = function(nPositionPercent)
  483. {
  484.    if(isNaN(parseFloat(nPositionPercent)))
  485.    {
  486.       nPositionPercent = 0;
  487.    }
  488.    nPositionPercent = Math.min(Math.max(nPositionPercent,0),100);
  489.    var nFrame = Math.round(nPositionPercent * (this.videoTarget._totalframes / 100)) + 1;
  490.    if(this.isPlaying)
  491.    {
  492.       this.videoTarget.gotoAndPlay(nFrame);
  493.    }
  494.    else
  495.    {
  496.       this.videoTarget.gotoAndStop(nFrame);
  497.    }
  498.    this.nPositionPercent = nPositionPercent;
  499. };
  500. _global.videoNavigationCLASS.prototype.getSliderPosition = function()
  501. {
  502.    return this.nPositionPercent;
  503. };
  504. _global.videoNavigationCLASS.prototype.onSliderPosition = function()
  505. {
  506.    this.POSITION_SLIDER.hitArea._x = this.POSITION_SLIDER_BAR.hitArea._x + this.POSITION_SLIDER_BAR.hitArea._width / 100 * (100 * this.videoTarget._currentframe / this.videoTarget._totalframes);
  507. };
  508. _global.videoNavigationCLASS.prototype.onPositionSliderBarPress = function()
  509. {
  510.    this.positionSliderDrag = setInterval(this,"onPositionSliderDrag",20);
  511.    this.tmpSlideisPlaying = this.isPlaying;
  512.    this.isPlaying = false;
  513. };
  514. _global.videoNavigationCLASS.prototype.onPositionSliderBarRelease = function()
  515. {
  516.    var sTrack;
  517.    clearInterval(this.positionSliderDrag);
  518.    this.onPositionSliderTarget[this.onPositionSliderMethod](this.nSliderPosition);
  519.    var position = this.POSITION_SLIDER_BAR.hitArea._parent._xmouse - this.POSITION_SLIDER_BAR.hitArea._x;
  520.    position /= this.POSITION_SLIDER_BAR.hitArea._width / 100;
  521.    this.isPlaying = this.tmpSlideisPlaying;
  522.    delete this.tmpSlideisPlaying;
  523.    this.setSliderPosition(position);
  524.    this.onPositionSliderDrag();
  525. };
  526. _global.videoNavigationCLASS.prototype.onPositionSliderPress = function()
  527. {
  528.    this.positionSliderDrag = setInterval(this,"onPositionSliderDrag",20);
  529.    this.tmpSlideisPlaying = this.isPlaying;
  530.    this.isPlaying = false;
  531. };
  532. _global.videoNavigationCLASS.prototype.onPositionSliderRelease = function()
  533. {
  534.    var sTrack;
  535.    clearInterval(this.positionSliderDrag);
  536.    this.onPositionSliderDrag();
  537.    this.isPlaying = this.tmpSlideisPlaying;
  538.    delete this.tmpSlideisPlaying;
  539.    var position = this.POSITION_SLIDER_BAR.hitArea._parent._xmouse - this.POSITION_SLIDER_BAR.hitArea._x;
  540.    position /= this.POSITION_SLIDER_BAR.hitArea._width / 100;
  541.    this.setSliderPosition(position);
  542.    this.onPositionSliderTarget[this.onPositionSliderMethod](this.nSliderPosition);
  543. };
  544. _global.videoNavigationCLASS.prototype.onPositionSliderDrag = function()
  545. {
  546.    updateAfterEvent();
  547.    this.POSITION_SLIDER.hitArea._x = Math.min(this.POSITION_SLIDER_BAR.hitArea._width + this.POSITION_SLIDER_BAR.hitArea._x,Math.max(this.POSITION_SLIDER_BAR.hitArea._x,this.POSITION_SLIDER_BAR.hitArea._parent._xmouse));
  548.    var position = this.POSITION_SLIDER_BAR.hitArea._parent._xmouse - this.POSITION_SLIDER_BAR.hitArea._x;
  549.    position /= this.POSITION_SLIDER_BAR.hitArea._width / 100;
  550.    this.setSliderPosition(position);
  551. };
  552.